/**
 * 算法思维：双指针
 * @param {number[]} nums
 * @return {number}
 */
const removeDuplicates = function(nums) {
  let target = 0
  for (let i = 1; i < nums.length; i++) {
    if (nums[target] !== nums[i]) {
      if (++target !== i) {
        nums[target] = nums[i]
      }
    }
  }
  return target + 1
};